package com.canyou.system.importhandler;

import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl;
import cn.hutool.core.util.StrUtil;

import java.text.DecimalFormat;
import java.util.Map;

/**
 * 用户导入处理类
 *
 * @author canyou
 * @date 20/02/27 17:34
 */
public class UserImportHandler extends ExcelDataHandlerDefaultImpl<Map<String, Object>> {

    private static final String MOBILE = "手机号码";

    @Override
    public void setMapValue(Map<String, Object> map, String originKey, Object value) {
        if (MOBILE.equals(originKey)) {
            try {
                value = new DecimalFormat().format(value).replace(",", "");
            } catch (Exception e) {
            }
        }
        map.put(getRealKey(originKey), value);
    }

    private String getRealKey(String originKey) {
        String newKey = StrUtil.EMPTY;
        switch (originKey) {
            case "用户名":
                newKey = "username";
                break;
            case "姓名":
                newKey = "realName";
                break;
            case "性别":
                newKey = "sex";
                break;
            case MOBILE:
                newKey = "mobile";
                break;
            case "组织":
                newKey = "orgName";
                break;
            case "部门":
                newKey = "deptName";
                break;
            case "角色":
                newKey = "roleName";
                break;
            case "出生日期":
                newKey = "birthday";
                break;
            case "邮箱":
                newKey = "email";
                break;
            default:
                break;
        }
        return newKey;
    }
}
